Skip to content

feat(django): Gate user identity behind data_collection config#6868

Merged
ericapisani merged 2 commits into
masterfrom
py-2583-django-user-info
Jul 24, 2026
Merged

feat(django): Gate user identity behind data_collection config#6868
ericapisani merged 2 commits into
masterfrom
py-2583-django-user-info

Conversation

@ericapisani

@ericapisani ericapisani commented Jul 23, 2026

Copy link
Copy Markdown
Member

Apply the data_collection.user_info setting to Django user identity (id, email, username) collection, giving it precedence over the legacy send_default_pii boolean when explicitly configured. This mirrors the existing behavior for client IP/user info already shipped for Flask, WSGI, and ASGI.

The user extraction logic in _after_get_response is pulled into a shared helper used by both the WSGI and ASGI event processors, and the parametrized send_default_pii/data_collection test matrix is extracted into tests/integrations/django/utils.py for reuse across the WSGI and ASGI test suites.

Refs PY-2583
Refs #6746

@linear-code

linear-code Bot commented Jul 23, 2026

Copy link
Copy Markdown

PY-2583

@ericapisani
ericapisani force-pushed the py-2583-django-user-info branch from cb1a6ba to 0f5f3fa Compare July 23, 2026 13:43
@ericapisani
ericapisani marked this pull request as ready for review July 23, 2026 13:44
@ericapisani
ericapisani requested a review from a team as a code owner July 23, 2026 13:44
@ericapisani
ericapisani marked this pull request as draft July 23, 2026 13:54
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

96422 passed | ⏭️ 6370 skipped | Total: 102792 | Pass Rate: 93.8% | Execution Time: 351m 29s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +522
Passed Tests 📈 +492
Failed Tests
Skipped Tests 📈 +30

All tests are passing successfully.

✅ Patch coverage is 85.37%. Project has 2513 uncovered lines.
✅ Project coverage is 89.67%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/django/init.py 82.86% ⚠️ 6 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.67%    89.67%        —%
==========================================
  Files          193       193         —
  Lines        24321     24337       +16
  Branches      8572      8586       +14
==========================================
+ Hits         21809     21824       +15
- Misses        2512      2513        +1
- Partials      1397      1399        +2

Generated by Codecov Action

@ericapisani
ericapisani marked this pull request as ready for review July 23, 2026 14:33
Comment thread tests/integrations/django/asgi/test_asgi.py
Apply the data_collection.user_info setting to Django user identity (id, email, username) collection, giving it precedence over the legacy send_default_pii boolean when explicitly configured. This mirrors the existing behavior for client IP/user info already shipped for Flask, WSGI, and ASGI.

The user extraction logic in _after_get_response is pulled into a shared helper used by both the WSGI and ASGI event processors, and the parametrized send_default_pii/data_collection test matrix is extracted into tests/integrations/django/utils.py for reuse across the WSGI and ASGI test suites.

Refs PY-2583
The new test was the only DB-touching test without @pytest.mark.forked. Running in the parent process leaked the created user into the shared in-memory sqlite DB (UNIQUE constraint failures in test_basic) and caused the parent to hold the session-scoped django_db_setup fixture, so forked children skipped postgres test DB creation but still destroyed it on teardown (database does not exist errors).
@ericapisani
ericapisani force-pushed the py-2583-django-user-info branch from 615580f to 4ee42d0 Compare July 23, 2026 18:15

@sentrivana sentrivana left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Just one comment/question.

assert response["body"] == b"handled by async process_exception"


@pytest.mark.forked

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the @pytest.mark.forked here? It tends to take longer and it sometimes causes hard to debug problems with tests, so if it's not necessary, would be better to omit it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the @pytest.mark.forked here?

I think we might - this is a copy/paste from database-related tests in the test_data_scrubbing file and my understanding from it is that any time a test touches a database, we need this decorator to isolate state.

I might've come to an incorrect understanding though, so please let me know if that's not quite right.

@ericapisani
ericapisani merged commit 814cf6f into master Jul 24, 2026
146 checks passed
@ericapisani
ericapisani deleted the py-2583-django-user-info branch July 24, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants